package com.sec.etech.file.service;

import com.sec.etech.file.mapper.EtechFileTaskMapper;
import com.sec.etech.file.model.EtechFileTask;
import com.sec.etech.sys.util.ContextUtil;
import org.openbpm.base.core.id.IdUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class EtechFileTaskService {
    @Resource
    private EtechFileTaskMapper etechFileTaskMapper;

    private int save(String fileId) {
        EtechFileTask task = new EtechFileTask();
        task.setFiletaskid(IdUtil.getUId());
        task.setFileid(fileId);
        task.setStatus(0);
        task.setPostuid(Long.parseLong(ContextUtil.getCurrentUserId()));
        task.setPostdate(new Date());
        return etechFileTaskMapper.insert(task);
    }

    public int createTask(String fileId, String suffix) {
        if(suffix!=null && ("txt,pdf,bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg," +
                "psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp,avif,apng").contains(suffix)) {
            return 0;
        }else {
            return this.save(fileId);
        }
    }
}
